import time

from jSort import *


def checkSort(a):
    for i in range(1, len(a)):
        if a[i - 1] > a[i]:
            return False
    return True

def insertion(a):
    print 'insertion sorting.....'
    start = time.clock()
    res = insertionSort(a)
    end = time.clock()
    print 'the checkSort of sorted data is: ' + str(checkSort(res))
    print 'cost of insertion sort is: ' + str(end - start) + 's'
    return res

def bubble(a):
    print 'bubble sorting.....'
    start = time.clock()
    res = bubbleSort(a)
    end = time.clock()
    print 'the checkSort of sorted data is:' + str(checkSort(res))
    print 'cost of bubble sort is: ' + str(end - start) + 's'
    return res

def selection(a):
    print 'selection sorting.....'
    start = time.clock()
    res = selectionSort(a)
    end = time.clock()
    print 'the checkSort of sorted data is:' + str(checkSort(res))
    print 'cost of selection sort is: ' + str(end - start) + 's'
    return res

# get random data
fs = open('data/sequnce-10000-1-10000.txt', 'r')
contents = fs.read()
fs.close()
a = contents.split(' ')
a = map(int, a)
# test for insertion sort
insertion(a+[])
# bubble(a+[])
selection(a+[])